package cnooc.energy.controller;


import cnooc.common.annotation.Log;
import cnooc.common.core.controller.BaseController;
import cnooc.common.core.domain.AjaxResult;
import cnooc.common.core.page.TableDataInfo;
import cnooc.common.enums.BusinessType;
import cnooc.common.enums.StatusEnums;
import cnooc.common.utils.poi.ExcelUtil;
import cnooc.energy.domain.Equipment;
import cnooc.energy.service.IEquipmentService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备配置Controller
 * 
 * @author 韩是非
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/energy/equipment")
public class EquipmentController extends BaseController
{
    @Autowired
    private IEquipmentService equipmentService;

    /**
     * 查询设备配置列表
     */
    @PreAuthorize("@ss.hasPermi('energy:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Equipment equipment)  {
        startPage();
        List<Equipment> list = equipmentService.selectEquipmentList(equipment);
        return getDataTable(list);
    }

    /**
     * 导出设备配置列表
     */
    @PreAuthorize("@ss.hasPermi('energy:equipment:export')")
    @Log(title = "设备配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Equipment equipment) {
        List<Equipment> list = equipmentService.selectEquipmentList(equipment);
        ExcelUtil<Equipment> util = new ExcelUtil<Equipment>(Equipment.class);
        util.exportExcel(response, list, "设备配置数据");
    }

    /**
     * 获取设备配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('energy:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(equipmentService.selectEquipmentById(id));
    }

    /**
     * 新增设备配置
     */
    @PreAuthorize("@ss.hasPermi('energy:equipment:add')")
    @Log(title = "设备配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Equipment equipment) {
        return toAjax(equipmentService.insertEquipment(equipment));
    }

    /**
     * 修改设备配置
     */
    @PreAuthorize("@ss.hasPermi('energy:equipment:edit')")
    @Log(title = "设备配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Equipment equipment) {
        return toAjax(equipmentService.updateEquipment(equipment));
    }

    /**
     * 删除设备配置
     */
    @PreAuthorize("@ss.hasPermi('energy:equipment:remove')")
    @Log(title = "设备配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(equipmentService.deleteEquipmentByIds(ids));
    }

    /**
     * 查询设备列表
     */
    @GetMapping("/deviceLists/{queryClass}")
    public AjaxResult deviceLists(@PathVariable String queryClass) {
        Equipment equipment = new Equipment();
        equipment.setStatus(StatusEnums.ENABLE.getValue());
        equipment.setQueryClass(queryClass);
        return success(equipmentService.selectEquipmentList(equipment));
    }

    /**
     * 查询所有设备列表
     */
    @GetMapping("/deviceListsAll")
    public AjaxResult deviceListsAll()
    {
        return success(equipmentService.selectEquipmentList(new Equipment()));
    }




    @GetMapping("/deviceWaring")
    public AjaxResult deviceWaring() {
        return AjaxResult.success(equipmentService.deviceWaring());

    }

}
